(function () {
    Codestrong.ui.CreateLectureDetail= function (_args) {

	var aps='';
	var mobilier = [],olecture;
	if(Ti.Platform.osname== 'android') {
  		 Titanium.include('../globals.js');
  		 aps='../';
    }
    else {
   		  Titanium.include('globals.js');
    }
	var ScrollViewMain ;
	var LectureDetail_Comment;
	var LectureDetail_InfoLecture;
	var LectureDetail_ListVideoRelate;
	
	
	
	/////////////////////FUNCTION//////////
	
	var LoadListVideo = function(LectureId,TypeID) {
	
    	var jsonurl=Globals.serviceurl_GetListVideo;
    	var param = {        
		  "LectureId" : LectureId,
		  "TypeID" : TypeID
		};
    	require('settings').GetJsonFunction(jsonurl,param,LoadListVideo_onload_table,LoadListVideo_error_even);
    	lbLoading.text='';
    	
	};
	var LoadListVideo_onload_table = function(e) {
		var datajson=e.datajson;
 		
    	for (i = 0; i < datajson.length; i++) {
				olecture = datajson[i];
				mobilier[i]=olecture;
		}
		PopularDataVideo(mobilier);
		
		LoadComment(_args.LectureId);
	};
	
	
	
	var LoadListVideo_error_even = function(e) {
		lbLoading.text=Globals.loadingTimeout;
	
	};
	var LoadComment = function(LectureId) {
	
		var Jsonurl=Globals.serviceurl_GetListLectureComment;
    	var param = {        
		  "LectureId" : LectureId,
		};
		require('settings').GetJsonFunction(Jsonurl,param,LoadComment_onload_table,LoadComment_error_even);
	};
	var LoadComment_onload_table = function(e) {
		
		var datajson=e.datajson;
		
		LectureDetail_Comment=require('controls/LectureDetail_Comment').LectureDetail_Comment({
			  topview:LectureDetail_ListVideoRelate.top+LectureDetail_ListVideoRelate.height,
			  backgroundImage_viewheader:aps+'images/panel.png',
			  height_viewheader:45,
			  infolabel:'Ý kiến thành viên',
			  datajson: datajson,
			
		})
		ScrollViewMain.add(LectureDetail_Comment);  
		Codestrong.ui.activityIndicator.hideModal();
	};
	var LoadComment_error_even = function(e) {
		lbLoading.text=Globals.loadingTimeout;
		Codestrong.ui.activityIndicator.hideModal();
	};
	
	
	
	var win = Titanium.UI.createWindow({
            id: 'lectureWindow1',
           // title: _args.TenMonHoc,//_args.LectureName,
            backgroundColor: '#FFF',
            barColor: '#414444',
            fullscreen: false
    });
    var egc = new globals.EventGarbageCollection(win);

	
	
   
   
    egc.addEventListener('back_LectureDetail', function () {
 		
 		Codestrong.navGroup.close(win, {
                        animated: true
        });
        
	});
	egc.addEventListener('LectureDetail:btMuaBaiGiangPopup', function (param) {
		
			spMuabaigiangPopup(param);
	});
    egc.addEventListener('LectureDetail:btMuaBaiGiang', function (param) {
			spMuabaigiang(param);
	});
	egc.addEventListener('LectureDetail:btMuaChuongTrinh', function () {
			spMuachuongtrinh();
	});
	egc.addEventListener('LectureDetail:btKichHoatTai', function () {
			spKichHoatTai();
	});
	egc.addEventListener('LectureDetail:btSeeLecture', function () {
			spSeeLecture();
	});
	egc.addEventListener('LectureDetail:btLike', function () {
			spLikebaigiang();
	});

	egc.addEventListener('LectureDetail:btDowloadLecture', function () {
			spDownloadLecture();
	});
	egc.addEventListener('LectureDetail:playvideoinTable', function (param) {
			spplayvideoinTable(param);
	});
	



	
    spMuabaigiangPopup = function(param)
	{
		
		var table = Ti.UI.createTableView();
			var BuyLecturePop = require('windows/BuyLecturePop').CreateBuyLecturePop
			var pop = new BuyLecturePop({
		      
		        view: table,
		        top:0,
		        isCheck:0,//Login Setting,
		        LectureId:param.LectureId
		    });
		pop.open();
		
		
	}
	spMuabaigiang = function(param1)
	{
		
	
		
		
		var confirm = Titanium.UI.createAlertDialog({ 
					            title: Globals.title, 
					            message:Globals.lbMuabaigiangqs, 
					            buttonNames: [Globals.btMuaBaiGiang,Globals.btCancel]
					    });
		confirm.addEventListener('click', function(e) {
		  
		       //Clicked cancel, first check is for iphone, second for android
		       if (e.cancel === e.index || e.cancel === true) {
		          return;
		       }
		 
		        //now you can use parameter e to switch/case
		 //	alert(Ti.App.Properties.getString('login_username_id')+'____'+Ti.App.Properties.getInt('LectureID'))
		       switch (e.index) {
		          case 0: {
		          			var param = {        
							  "UserId" : Ti.App.Properties.getInt('login_username_id'),//577258,  //User:thai@gmail.com
							  "LectureId" : param1.LectureId,//Ti.App.Properties.getInt('LectureID'),
							  "Price" : 2000
						    };
						
							var xhr = Titanium.Network.createHTTPClient({
								   onload : function(e) 
								   {
								       Titanium.API.info(this.responseText);
									   json = this.responseText;
									   json=json.replace('<string xmlns="http://tempuri.org/">', '');
									   json=json.replace('<?xml version="1.0" encoding="utf-8"?>', '');
									   json=json.replace('</string>', '');
									  // alert(json)
									   if(json==1)//sucessfull
										{
											Ti.App.Properties.setInt('IsBuyLectureID', 1);
											require('settings').createAlertDialog(Globals.title,Globals.ListVideoWindow_BuyView_success);
										}
										else if(json==2)//khong du tien
										{
											require('settings').createAlertDialog(Globals.title,Globals.ListVideoWindow_BuyView_MoneyCard);
										}
										else//error
										{
											require('settings').createAlertDialog(Globals.title,Globals.ListVideoWindow_BuyView_unsuccess);
										}
								   },
								   onerror : function(e) {
								    
								   },
								   timeout : Globals.timeout//5000
						    
							});
							xhr.open("POST",Globals.serviceurl_UserLectureBuy);
							xhr.send(param);
						  }
		          break;
		 
		          //This will never be reached, if you specified cancel for index 1
		          case 1: Titanium.API.info('Clicked button 1 (NO)');
		          break;
		 
		          default:
		          break;
		      }
		 
		});
		confirm.show(); 
		
	}
	spMuachuongtrinh= function()
	{
		var confirm = Titanium.UI.createAlertDialog({ 
					            title: Globals.title, 
					            message:Globals.lbMuachuongtrinhqs, 
					            buttonNames: [Globals.btMuaChuongTrinh,Globals.btCancel]
					    });
		confirm.addEventListener('click', function(e) {
		  
		       //Clicked cancel, first check is for iphone, second for android
		       if (e.cancel === e.index || e.cancel === true) {
		          return;
		       }
		 
		        //now you can use parameter e to switch/case
		 
		       switch (e.index) {
		          case 0: {
		          			var param = {        
							  "UserId" :Ti.App.Properties.getInt('login_username_id'),// 577258,
							  "ServiceId" : 6,
							  "Price" : 200000
						    };
						
							var xhr = Titanium.Network.createHTTPClient({
								   onload : function(e) 
								   {
								       Titanium.API.info(this.responseText);
									   json = this.responseText;
									   json=json.replace('<string xmlns="http://tempuri.org/">', '');
									   json=json.replace('<?xml version="1.0" encoding="utf-8"?>', '');
									   json=json.replace('</string>', '');
									  // alert(json)
									   if(json==1)//sucessfull
										{
											Ti.App.Properties.setInt('IsBuyProgram', 1);
											require('settings').createAlertDialog(Globals.title,Globals.ListVideoWindow_BuyViewProgram_success);
											
										}
										else if(json==2)//khong du tien
										{
											require('settings').createAlertDialog(Globals.title,Globals.ListVideoWindow_BuyView_MoneyCard);
											
										}
										else//error
										{
											require('settings').createAlertDialog(Globals.title,Globals.ListVideoWindow_BuyViewProgram_unsuccess);
										}
								   },
								   onerror : function(e) {
								    
								   },
								   timeout :Globals.timeout// 5000
						    
							});
							xhr.open("POST",Globals.serviceurl_UserServiceBuy);
							xhr.send(param);
						  }
		          break;
		 
		          //This will never be reached, if you specified cancel for index 1
		          case 1: Titanium.API.info('Clicked button 1 (NO)');
		          break;
		 
		          default:
		          break;
		      }
		 
		});
		confirm.show(); 
	}
	spKichHoatTai= function()
	{
		var confirm = Titanium.UI.createAlertDialog({ 
					            title: Globals.title, 
					            message:Globals.lbKichhoatTaiqs, 
					            buttonNames: [Globals.btKichHoatTai,Globals.btCancel]
					    });
		confirm.addEventListener('click', function(e) {
		  
		       //Clicked cancel, first check is for iphone, second for android
		       if (e.cancel === e.index || e.cancel === true) {
		          return;
		       }
		 
		        //now you can use parameter e to switch/case
		 
		       switch (e.index) {
		          case 0: {
		          				var param = {        
								  "UserId" :Ti.App.Properties.getInt('login_username_id'),// 577258,
								  "ServiceId" : 7,
								  "Price" : 100000
							    };
							
								var xhr = Titanium.Network.createHTTPClient({
									   onload : function(e) 
									   {
									       Titanium.API.info(this.responseText);
										   json = this.responseText;
										   json=json.replace('<string xmlns="http://tempuri.org/">', '');
										   json=json.replace('<?xml version="1.0" encoding="utf-8"?>', '');
										   json=json.replace('</string>', '');
										  // alert(json)
										   if(json==1)//sucessfull
											{
												require('settings').createAlertDialog(Globals.title,Globals.ListVideoWindow_BuyViewDownload_success);
												Ti.App.Properties.setInt('IsActiveDownload', 1);
												
											}
											else if(json==2)//khong du tien
											{
												require('settings').createAlertDialog(Globals.title,Globals.ListVideoWindow_BuyView_MoneyCard);
												
											}
											else//error
											{
												require('settings').createAlertDialog(Globals.title,Globals.ListVideoWindow_BuyViewDownload_unsuccess);
											}
									   },
									   onerror : function(e) {
									    
									   },
									   timeout : Globals.timeout//5000
							    
								});
								xhr.open("POST",Globals.serviceurl_UserServiceBuy);
								xhr.send(param);
						  }
		          break;
		 
		          //This will never be reached, if you specified cancel for index 1
		          case 1: Titanium.API.info('Clicked button 1 (NO)');
		          break;
		 
		          default:
		          break;
		      }
		 
		});
		confirm.show(); 
	}
	
	spplayvideoinTable= function(param)
	{
		if(param.Index<=2)
		{
			//alert(param.Index-1)
			var it=mobilier[param.Index-1]
			//Play bai giang ko can kiem tra
			spPlayVideo(it.VideoUrl)
		}
		else
		{
			//Kiem tra bai giang
			spSeeLecture_InTable(param.Index)
		}
	}
	spSeeLecture= function()
	{
		if (Ti.Network.online) {
			if(Ti.App.Properties.getInt('isLogin')==1)
			{
				//Kiem tra bai giang co duoc mua chua
				var param = {        
				  "UserId" :Ti.App.Properties.getString('login_username_id'),// 577258,
				  "lectureId" :_args.LectureId
				
			    };
			
				var xhr = Titanium.Network.createHTTPClient({
				   onload : function(e) 
				   {
				       Titanium.API.info(this.responseText);
					   json = this.responseText;
					   json=json.replace('<string xmlns="http://tempuri.org/">', '');
					   json=json.replace('<?xml version="1.0" encoding="utf-8"?>', '');
					   json=json.replace('</string>', '');
					   
					   spSeeLecture_SeeAll(json)
				   },
				   onerror : function(e) {
				      Ti.App.Properties.setInt('IsBuyLectureID',0);
				   },
				   timeout : Globals.timeout// 5000
				});
				xhr.open("POST",Globals.serviceurl_CheckLectureUser);
				xhr.send(param);
				
			}
			else{
			
				
				var title='Bạn chưa đăng nhập nên chỉ xem được 2 phần đầu tiên';
				var	options= ['Phần 1','Phần 2',Globals.btCancel];
				spSeeLecture_See2Part(title,options)
			}
		 }
		 else
		 {
		  	   require('settings').createAlertConnectError();
		 }
		 	
	}
	spSeeLecture_InTable= function(Index)
	{
		if (Ti.Network.online) {
			if(Ti.App.Properties.getInt('isLogin')==1)
			{
				//Kiem tra bai giang co duoc mua chua
				var param = {        
				  "UserId" :Ti.App.Properties.getString('login_username_id'),// 577258,
				  "lectureId" :_args.LectureId
				
			    };
			
				var xhr = Titanium.Network.createHTTPClient({
				   onload : function(e) 
				   {
				       Titanium.API.info(this.responseText);
					   json = this.responseText;
					   json=json.replace('<string xmlns="http://tempuri.org/">', '');
					   json=json.replace('<?xml version="1.0" encoding="utf-8"?>', '');
					   json=json.replace('</string>', '');
					   
					   spSeeLecture_SeeAll_InTable(json,Index)
				   },
				   onerror : function(e) {
				      Ti.App.Properties.setInt('IsBuyLectureID',0);
				   },
				   timeout : Globals.timeout// 5000
				});
				xhr.open("POST",Globals.serviceurl_CheckLectureUser);
				xhr.send(param);
				
			}
			else{
				var title='Bạn chưa đăng nhập nên chỉ xem được 2 phần đầu tiên';
				var	options= ['Phần 1','Phần 2',Globals.btCancel];
				spSeeLecture_See2Part(title,options)
			}
		 }
		 else
		 {
		  	   require('settings').createAlertConnectError();
		 }
		 	
	}
	spPlayVideo= function(urlvideo)
	{
		Codestrong.navGroup.open(Codestrong.ui.createVideoPlayWindow({
								        VideoUrl:  urlvideo}), 
									    { 
									        animated: true,
		    								navBarHidden:true
									    });	
	}
	
	spCreateOptionDialog= function(title,options)
	{
		var confirm = Titanium.UI.createOptionDialog({ 
				      title:title,
				      options: options,
				        
		});
		confirm.show(); 
		return confirm
	}
	
	
	spSeeLecture_See2Part= function(title,options)
	{
		
		var confirm=spCreateOptionDialog(title,options);
		confirm.addEventListener('click', function(e) {
		       switch (e.index) {
		          case 0: {
		          				//Phan 1
		          				var p1=mobilier[0];
		          				spPlayVideo(p1.VideoUrl)
		          				
						  }
		          break;
		 
		          
		          case 1: {
		          				//Phan 2
		          				var p2=mobilier[1];
		          				spPlayVideo(p2.VideoUrl)
						  }
		          break;
		 		
		          default:
		          break;
		      }
		});
	}
	
	
	
	spSeeLecture_SeeAll= function(IsSee)
	{
		//alert(mobilier[0])
		
		if(IsSee==0)
		{
			//Chua mua bai giang
			var title='Bạn chưa mua bài giảng nên chỉ xem được 2 phần đầu tiên';
			var	options= ['Phần 1','Phần 2',Globals.btCancel];
			spSeeLecture_See2Part(title,options)
		}
		else
		{
			//Da mua bai giang
			var length=mobilier.length
			var buttonNames=[]
			var i = 1
			for( i = 1; i <= length; i++) {
				buttonNames[i-1]=mobilier[i-1].Name
			}
			buttonNames[i-1]='Xem tất cả'
			buttonNames[i]=Globals.btCancel
			
		
			var title='Chọn phần cần xem';
			var	options= buttonNames;
			var confirm=spCreateOptionDialog(title,options);
			confirm.addEventListener('click', function(e) {
		   		if(e.index==buttonNames.length-1)
		   		{
		   			//Huy bo
		   			//alert('Huy bo')
		   			
		   			
		   		}
		   		else if(e.index==buttonNames.length-2)
		   		{
		   			//Xem tat ca
		   			//alert('Xem tat ca')
		   			var a=mobilier[0];
		   			spPlayVideo(a.VideoUrl)
		   		}
		   		else 
		   		{
		   			//Xem cac phan
		   			//alert('Xem phan'+(e.index+1))
		   			var a=mobilier[e.index];
		   			spPlayVideo(a.VideoUrl)
		   		}
			});
		}
	}
	spSeeLecture_SeeAll_InTable= function(IsSee,Index)
	{
		//alert(mobilier[0])
		
		if(IsSee==0)
		{
			//Chua mua bai giang
			var title='Bạn chưa mua bài giảng nên chỉ xem được 2 phần đầu tiên';
			var	options= ['Phần 1','Phần 2',Globals.btCancel];
			spSeeLecture_See2Part(title,options)
		}
		else
		{
			// Index
   			//Xem cac phan theo index bai giang
   		
   		   var vt=mobilier[Index-1];
   		   spPlayVideo(vt.VideoUrl)
		   	
		}
	}
	
	spDownloadLecture= function()
	{	
		if (Ti.Network.online) {
			
				//Kiem tra bai giang co duoc mua chua
				var param = {        
				  "UserId" :Ti.App.Properties.getString('login_username_id'),// 577258,
				  "lectureId" :_args.LectureId
				
			    };
			
				var xhr = Titanium.Network.createHTTPClient({
				   onload : function(e) 
				   {
				       Titanium.API.info(this.responseText);
					   json = this.responseText;
					   json=json.replace('<string xmlns="http://tempuri.org/">', '');
					   json=json.replace('<?xml version="1.0" encoding="utf-8"?>', '');
					   json=json.replace('</string>', '');
					 
					   spCheckDownloadLecture(json)
				   },
				   onerror : function(e) {
				      
				   },
				   timeout : Globals.timeout// 5000
				});
				xhr.open("POST",Globals.serviceurl_CheckLectureUserDownload);
				xhr.send(param);
				
			
			
		 }
		 else
		 {
		  	   require('settings').createAlertConnectError();
		 }
	}
	spCheckDownloadLecture= function(IsDownload)
	{	
		//alert(_args.IsSee +'MM'+_args.IsDownload)
		//Chua mua bai giang va chua kich hoat tai bai giang
		if(IsDownload==1)
		{
			
			
			var confirm = Titanium.UI.createAlertDialog({ 
					            title: Globals.title, 
					            message:'Vui lòng mua bài giảng này và kích hoạt chức năng tải để tải bài giảng', 
					            buttonNames: ['Mua bài giảng',Globals.btCancel]
					    });
			confirm.addEventListener('click', function(e) {
			       //Clicked cancel, first check is for iphone, second for android
			       if (e.cancel === e.index || e.cancel === true) 
			          return;
			          
			       switch (e.index) {
			          case 0: {
			          			 Ti.App.fireEvent('LectureDetail:btMuaBaiGiangPopup',{LectureId:_args.LectureId})
					  }
			          break;
			         
			 
			          default:
			          break;
			      }
			 
			});
			confirm.show(); 
		}
		//return;
		
		//Da mua bai giang va da kich hoat tai bai giang
		if(IsDownload==2)
		{
			var length=mobilier.length
			var buttonNames=[]
			var i = 1
			for( i = 1; i <= length; i++) {
				buttonNames[i-1]=mobilier[i-1].Name
			}
			buttonNames[i-1]='Tải tất cả'
			buttonNames[i]=Globals.btCancel
			
		
			var title='Chọn phần cần tải';
			var	options= buttonNames;
			var confirm=spCreateOptionDialog(title,options);
			confirm.addEventListener('click', function(e) {
		   		if(e.index==buttonNames.length-1)
		   		{
		   			//Huy bo
		   			//alert('Huy bo')
		   			
		   		}
		   		else if(e.index==buttonNames.length-2)
		   		{
		   			//Tai tat ca
		   			//alert('Tai tat ca')
		   			var item={
						LectureId:_args.LectureId,
						LectureName:_args.LectureName,
						Price:_args.Price,
						TeacherImage:_args.TeacherImage,
						dataDownload:mobilier,
						IsDownloadAll:1
					}
				
		   			//alert(item)
		   			spDownloadPop(item);
		   		}
		   		else 
		   		{
		   			//Tai cac phan
		   			
					var item={
						LectureId:_args.LectureId,
						LectureName:_args.LectureName,
						Price:_args.Price,
						TeacherImage:_args.TeacherImage,
						dataDownload:mobilier,
						IsDownloadAll:0,
						Index:e.index
					}
		   			spDownloadPop(item);
		   		}
			});
		}
		//return;
	
		//Chua kich hoat tai bai giang ma da mua bai giang
		if(IsDownload==3)
		{
		
			
			var confirm = Titanium.UI.createAlertDialog({ 
					            title: Globals.title, 
					            message:'Vui lòng kích hoạt chức năng tải để tải bài giảng', 
					            buttonNames: ['Kích hoạt tải',Globals.btCancel]
					    });
			confirm.addEventListener('click', function(e) {
			       //Clicked cancel, first check is for iphone, second for android
			       if (e.cancel === e.index || e.cancel === true) 
			          return;
			          
			       switch (e.index) {
			          case 0: {
			          		 Ti.App.fireEvent('LectureDetail:btMuaBaiGiangPopup',{LectureId:_args.LectureId})		
					  }
			          break;
			         
			 
			          default:
			          break;
			      }
			 
			});
			confirm.show(); 
		}
		//return
		
		//Da kich hoat tai bai giang ma chua mua bai giang
		if(IsDownload==4)
		{
		
			
			var confirm = Titanium.UI.createAlertDialog({ 
					            title: Globals.title, 
					            message:'Vui lòng mua bài giảng này để tải bài giảng này về máy', 
					            buttonNames: ['Mua bài giảng',Globals.btCancel]
					    });
			confirm.addEventListener('click', function(e) {
			       //Clicked cancel, first check is for iphone, second for android
			       if (e.cancel === e.index || e.cancel === true) 
			          return;
			          
			       switch (e.index) {
			          case 0: {
			          				 Ti.App.fireEvent('LectureDetail:btMuaBaiGiangPopup',{LectureId:_args.LectureId})
					  }
			          break;
			         
			 
			          default:
			          break;
			      }
			 
			});
			confirm.show(); 
		}
	}
	
	spDownloadPop= function(item)
	{
		var table = Ti.UI.createTableView();
		var Download = require('windows/DownloadPop').CreateDownloadPop
		var pop = new Download({
	        title: Globals.login_login,
	        view: table,
	        top:0,
	        item:item,
	      
	       // isCheck:0//Login Setting
	    });
	    pop.open();
	}
	
	
	spLikebaigiang= function()
	{
		alert('Đang xây dựng chức năng,vui lòng quay lại sau')
	}
	////////////main_header///////////////////////////
	 var databutton_right=[
    	{Id:1,Image:aps+'images/list_bullets.png',Image_:aps+'images/list_bullets_.png',tag:'Category'},
	    {Id:2,Image:aps+'images/account.png',Image_:aps+'images/account_.png',tag:'Login'},
	    //{Id:3,Image:aps+'images/search.png',Image_:aps+'images/search_.png',tag:'Search'},
	    
	]
	
	
	var main_header=require('controls/main_header').main_header({
	 		backgroundImage: aps+'images/panel3.png',
	 		headertext: 'Thầy trò Mobile: '+ _args.TenMonHoc,//_args.LectureName,
		    left: 0,
		    top: 0,
		    height:65,
		    width: '100%',//Globals.platformWidth,
		    touchEnabled: true		,
		    databutton_right:databutton_right,
		   
		    imback:   aps+'images/back.png',
		    imback_:   aps+'images/back_.png',
		    idWinParent:'LectureDetail',
    })

	win.add(main_header);
	
	////////////LectureDetail_header///////////////////////////

	var LectureDetail_header=require('controls/LectureDetail_header').LectureDetail_header({
	 		backgroundImage: aps+'images/sessionbckgd.png',
	 		
		    left: 0,
		    top: main_header.top+main_header.height,
		    height:155,
		    width: '100%',//Globals.platformWidth,
		    touchEnabled: true		,
		    backgroundImage_ImageTitle:aps+'images/teacher/'+_args.TeacherImage,
		    lbLectureName:_args.LectureName,
		 	lbPrice:_args.Price,
		 	btheight_button:45,
		 	
		 	LectureId:_args.LectureId
		    
    })

	win.add(LectureDetail_header);
	
	
	
   ScrollViewMain = Ti.UI.createScrollView({
		top:LectureDetail_header.top+LectureDetail_header.height,
		
		touchEnabled:true,
		//height:'100%',
		scrollsToTop:true,
		
	});
	var lbLoading = Ti.UI.createLabel({
		text:Globals.loading,
		color:'#1e6cc1',
		font:{
			fontSize:Ti.App.Properties.getString('fontsizeLarge'),
			fontWeight:'bold'
		},
	});
	ScrollViewMain.add(lbLoading)
	
	

	var PopularDataVideo = function(dataVideo) {
		
		var Items=dataVideo,countitemt=0,rowindex=0;
		var top_t=0
		var IsMod=0
		var lengthData=Items.length
		
	    switch (lengthData) {
		          case 0: {countrow=0;}
		          break;
		          case 1: {countrow=1;}
		          break;
		          case 2: {countrow=1;}
		          break;
		          case 3: {countrow=1;}
		          break;
		          case 4: {countrow=1;}
		          break;
		          case 5: {countrow=2;}
		          break;
		          case 6: {countrow=2;}
		          break;
		          case 7: {countrow=2;}
		          break;
		          case 8: {countrow=2;}
		          break;
		          case 9: {countrow=3;}
		          break;
		          case 10: {countrow=3;}
		          break;
		          case 11: {countrow=3;}
		          break;
		          case 12: {countrow=3;}
		          break;
		          case 13: {countrow=4;}
		          break;
		          case 14: {countrow=4;}
		          break;
		          case 15: {countrow=4;}
		          break;
		          case 16: {countrow=4;}
		          break;
		 
		          default:
		          break;
		      }
		
		

	
	   var vi = Ti.UI.createView({
				height:countrow*Globals.platformWidth/4,
				width:Globals.platformWidth,
				top:0,
				backgroundImage:aps+'images/Dark.png',
				borderRadius:0,
				borderColor:'black',
				borderWidth:1,
				touchEnabled:true,
		});
		
		ScrollViewMain.add(vi);
	
		
	//	alert('Leng'+lengthData+' Nguyen thuy'+lengthData/4+' Tron:'+Math.round((lengthData/4))) 
	
		for(var i = 1; i <= countrow; i++) {
			if(lengthData-4>0)
			{
				 countitemt = 4
				 lengthData-= 4
			}
			else
			{
				 countitemt = lengthData
			}
				
			var LectureDetail_tablerow=require('controls/LectureDetail_tablerow').LectureDetail_tablerow({
		 			top:top_t,
		  			height:Globals.platformWidth/4,
		  			width:'100%',//Globals.platformWidth,
					backgroundImage_Child:aps+'images/video-player.png',
					backgroundColorSection:'#2981a3',
					countitemt:countitemt,
					rowindex:i-1,
					IsDownload:_args.IsDownload,
					IsSee:_args.IsSee,
					LectureId:_args.LectureId
				
			    })
		   vi.add(LectureDetail_tablerow);
		   top_t+=Globals.platformWidth/4;
		}
		 
		ScrollViewMain.add(vi);
		
		///////////////THONG TIN//////////////
	
		 
		Load_InfoLecture(vi)
		Load_ListVideoRelate()
		
	
	
		
	}
	var Load_InfoLecture = function(vi) {
		 LectureDetail_InfoLecture=require('controls/LectureDetail_InfoLecture').LectureDetail_InfoLecture({
		  			 heightview:150,
					 widthview:'100%',//Globals.platformWidth,
					 leftview:0,
		  			 topview:vi.top+vi.height,
		  			 infolabel:'Thông tin bài giảng',
		  			 width_viewheader:'100%',//Globals.platformWidth,
		  			 height_viewheader:45,
		  			 backgroundImage_viewheader:aps+'images/panel.png',
		  			// url:url_buylecture,
		  		     dataLecture:_args.dataLecture
		})
		ScrollViewMain.add(LectureDetail_InfoLecture); 
	}
	var Load_ListVideoRelate = function() {
		//////////////BAI GIANG LIEN QUAN///////////////
	
		 LectureDetail_ListVideoRelate=require('controls/LectureDetail_ListVideoRelate').LectureDetail_ListVideoRelate({
		  			 heightview:158,
					 widthview:Globals.platformWidth,
					 backgroundImage:aps+'images/Dark.png',
					 leftview:0,
		  			 topview:LectureDetail_InfoLecture.top+LectureDetail_InfoLecture.height,
		  			 infolabel:'Danh sách bài giảng liên quan',
		  			 width_viewheader:'100%',//Globals.platformWidth,
		  			 height_viewheader:45,
		  			 backgroundImage_viewheader:aps+'images/panel.png',
					 dataLecture:_args.dataLecture	,
					 dataLectureArray:_args.dataLectureArray	,  
					 IdChuong:	_args.dataLecture.IdChuong	
		})
		ScrollViewMain.add(LectureDetail_ListVideoRelate);  
	}

	
	win.add(ScrollViewMain);
	/////////////////////////OPEN WINDOWN/////////////////////////
	
	
	
	 if (Ti.Network.online) {
			Codestrong.ui.activityIndicator.showModal(Globals.loading, Globals.timeout, Globals.loadingTimeout);
			LoadListVideo(_args.LectureId,_args.TypeID)
			
			
	 }
	 else
	 {

	  	    lbLoading.text=Globals.connecterror;
	 }
	///////////////////////////////////////////////////////////////
 	return win;
       
    };
})();